/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vectors;


import java.util.*;

/**
 *
 * @author Кирилл
 */
public class JVectorAdapter implements VectorIn{
    private Vector<Double> vector = null;
    private ArrayList observer;
   public JVectorAdapter(java.util.Vector<Double> vector){
      this.vector = new Vector(vector);
   };

    @Override
    public void setElement(double value, int index) {
       vector.set(index, value);
    }

    @Override
    public Double getElement(int index) {
          return vector.get(index);
    
    }

    @Override
    public int getSize() {
         return vector.size();
    }

    @Override
    public void massiveToVector(double[] massive) {
       vector = new Vector(massive.length);
       for (int i = 0; i < massive.length; i++) {
            vector.add(massive[i]);
    }
 }
    @Override
    public void objectToVector(VectorIn Vector1) {
      if (vector == null)
            throw new IllegalArgumentException("Null vector is not allowed");
        Iterator vectorIterator = vector.iterator();
        this.vector = new Vector(Vector1.getSize());
        int index = 0;
        while (vectorIterator.hasNext()) {
            vector.set(index, (Double) vectorIterator.next());
            index++;
        }
    };

    @Override
    public void multiplyVector(double multiply) {
     for (int i = 0; i < getSize();i++){
        this.vector.set(i,vector.get(i)*multiply);
     }   
}
    @Override
    public void vectorPlusVector(VectorIn Vector) {
          if(vector.size() != Vector.getSize()){
        System.out.print("Ошибка!Задайте другой размер.");
    }else{
         for(int i = 0; i < vector.size() && i < Vector.getSize(); i++){  
            vector.add(vector.get(i) + Vector.getElement(i));
    }
  }
 }        
    @Override
    public boolean equals(Object obj){
        if (obj == null)
            return false;
        if(!(obj instanceof VectorIn))
            return false;
        VectorIn vec = (VectorIn) obj;
        if (this.vector.size() != vec.getSize())
            return false;

        for (int i = 0; i < this.vector.size(); i++) {
            if(getElement(i) != vec.getElement(i))
                return false;
        }
        return true;
    }
    @Override
    public int hashCode(){
        int result = 0;
    for(double i : this.vector){
        long bits = Double.doubleToRawLongBits(i);
        result ^=((int)(bits & 0x00000000FFFFFFFFL)) ^ 
                                ((int)((bits & 0xFFFFFFFF00000000L) >> 32));
    }
    return result;
    }
    @Override
    public String toString(){
        return vector.toString();
    }
    @Override
    public Object clone() throws CloneNotSupportedException{
         JVectorAdapter result = null;
       result = (JVectorAdapter) super.clone();
       result.vector = (Vector<Double>)vector.clone();
    return result;
    }
    
    @Override
    public boolean equalsVectors(VectorIn Vector) {
           boolean f;
    if(vector.size() != Vector.getSize() )
          return false;
      for (int i = 0; i < vector.size(); i++){
          if(vector.get(i)!= Vector.getElement(i))
           return false;
}
          return true;
    }
    @Override
    public void add(double value) {
         vector.add(value);
    }

    @Override
    public Iterator<Double> iterator() {
    return vector.iterator();
    }

    @Override
    public void registerObserver(vectors.Observer o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void removeObserver(vectors.Observer o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void elementNotifyObservers(int index) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void updateNotifyObservers() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
    

}